﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TestWebApplication.CommerceAccount;

using TestWebApplication.CommerceTestDataProvider;
using System.Xml;
using System.IO;
using System.Security;
using System.Security.Cryptography.X509Certificates;
using Microsoft.CTP.CommerceAPI.SDKSample.Client.Api;
using Microsoft.CTP.CommerceAPI.Proxy.v201112;

namespace TestWebApplication
{
    public partial class login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String fileLocation = HttpContext.Current.Server.MapPath(Constants.CountriesLocation);
            fileLocation = fileLocation.Remove(fileLocation.IndexOf(ServiceSettings.Api), ServiceSettings.Api.Length + 1);
            XmlDocument xml = new XmlDocument();
            xml.Load(fileLocation);
            XmlElement root = xml.DocumentElement;
            foreach (XmlNode countryNode in root.ChildNodes)
            {
                countries.Items.Add(new ListItem()
                {
                    Text = countryNode.Attributes["name"].Value,
                    Value = countryNode.Attributes["value"].Value
                });
            }
        }
        protected void login2_Click(object sender, EventArgs e)
        {
            Session["locale"] = countries.SelectedValue;


            AccountInfoOutput account = AccountApi.SearchAccounts("PUID", puid.Text, "",
                   new SearchAccountFilters { CustomerType = Microsoft.CTP.CommerceAPI.Proxy.v201112.CustomerType.Personal, CountryCode = "US" }, AccountInfoDetailLevel.Default, a => true);
            Session["accountID"] = account.AccountId;
            Session["requester"] = CommerceAccountDataProvider.CreateIdentity(puid.Text, liveID.Text);

            //Response.Redirect("<script>window.open('www.baidu.com');</script>");
            Response.Redirect("MainPage.aspx");
        }

        protected void loginPartner_Click(object sender, EventArgs e)
        {
            Response.Redirect("ShowPurchases.aspx");
        }
    }
}